﻿// <copyright file="AttackSolvingService.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the batch service to resolve attacks from a queue with AttackSolver</summary>

namespace Sqwarea.Batch
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Lokad.Cloud;
    using Lokad.Cloud.ServiceFabric;
    using Lokad.Cloud.Services;
    using Lokad.Cloud.Storage;
    using Sqwarea.GameLogic;
    using Sqwarea.Persistence;
    using Sqwarea.Persistence.Azure;

    /// <summary>
    /// Service for resolving attacks using AttackSolver
    /// </summary>
    [QueueServiceSettings(
        AutoStart = true, 
        QueueName = GameProvider.AttackQueueName,
        ProcessingTimeoutSeconds = GlobalParameters.AttackSolverTimeOutSeconds)]
    public class AttackSolvingService : QueueService<Attack>
    {
        /// <summary>
        /// Gets or sets attacksolver (expected to be initialized by AutoFac)
        /// </summary>
        public IAttackSolver AttackSolver { get; set; }

        /// <summary>
        /// Entry point to the service of dealing with attacks
        /// </summary>
        /// <param name="message">The attack needed to be resolved, obtained from the queue.</param>
        protected override void Start(Attack message)
        {
            this.AttackSolver.ResolveAttack(message);
        }
    }
}
